<?php


namespace Frieza\Modules\RiskContent\Actions;

use Doraemon\module\ContentChecking\Common\AuditCommand;
use Doraemon\module\ContentChecking\Common\CheckLogConst;
use Doraemon\module\ContentChecking\Service\CheckLog;
use Doraemon\tools\Log;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

class SetPrevious4nick extends RowAction
{
    public $name = '置为修改前昵称';
    const TOAST_ALERT = '你确定要忽略此用户吗？';

    public function handle($logId,Request $request)
    {

        Log::error("reasonsViolation",[$request->input("reasonsViolation")]);

        $adminId = Admin::user()->id;

        $command = new AuditCommand();

        $command->adminId = $adminId;

        $command->Id = $logId;
        //$command->reasonsViolation = $request->input("reasonsViolation");

        $remarks['seasons'] =  $request->input("seasons",'');
        $remarks['feedback'] =  $request->input("feedback",'');
        $remarks['other_seasons'] =  $request->input("other_seasons",'');

        $isErr = empty($remarks['other_seasons']) && $remarks['seasons'] == CheckLogConst::VIOLATION_TYPE_OTHER
            || !empty($remarks['other_seasons']) && $remarks['seasons'] != CheckLogConst::VIOLATION_TYPE_OTHER;

        if($isErr){
            return $this->response()->error('违规原因必须选择其他,其他原因才能填写内容！');
        }


        $command->remarks['other_seasons'] = $remarks['other_seasons'];
        $command->remarks['seasons_num'] = $remarks['seasons'];
        $command->remarks['seasons'] = CheckLogConst::VIOLATION_TYPE_TEXT[$remarks['seasons']];
        $command->remarks['feedback'] = $remarks['feedback'];

        $checkLogService = new CheckLog();
        $res = $checkLogService->setPrevious4nick($command);
        if ($res) {
            return $this->response()->success('设置成功')->refresh();
        } else {
            return $this->response()->error('操作失败,稍后重试!');
        }


    }

    public function retrieveModel(Request $request)
    {

        Log::error("retrieveModel,reasonsViolation",[$request->input("reasonsViolation")]);

        if (!$key = $request->get('_key')) {
            return false;
        }

        Log::error("reasonsViolation",[$request->input("reasonsViolation")]);

        return $key;
    }


    public function form()
    {

        $this->select('seasons', '违规原因')->options(CheckLogConst::VIOLATION_TYPE_TEXT)->rules('required');

        $this->text("other_seasons","其他违规原因");

        $this->textarea('feedback', '话术');
    }
}